package scau.erps.service.impl;

import java.util.List;

import org.nutz.dao.Cnd;
import org.nutz.dao.util.cri.SqlExpressionGroup;
import org.nutz.service.IdEntityService;

import scau.erps.entity.SystemOrder;
import scau.erps.service.SystemOrderService;

public class SystemOrderServiceImpl extends IdEntityService<SystemOrder> implements SystemOrderService {

	/* 批量生成订单
	 * @see scau.erps.service.SystemOrderService#generateOrders(java.util.List)
	 */
	@Override
	public void generateOrders(List<SystemOrder> orders) {
		this.dao().insert(orders);					
	}

	/* 找到订单
	 * @see scau.erps.service.SystemOrderService#getSystemOrders(java.lang.String, java.lang.String, java.lang.String)
	 */
	@Override
	public List<SystemOrder> getSystemOrders(String year, String product,String market) {
		SqlExpressionGroup e1 = null;
		SqlExpressionGroup e2 = null;
		SqlExpressionGroup e3 = null;
		if(year != null){
			e1 = Cnd.exps("year", "=", year);			
		}
		if(product != null){
			e2 = Cnd.exps("product", "=", product);
		}
		if(market != null){
			e3 = Cnd.exps("market", "=", market);
		}
		return this.query(Cnd.where(e1).and(e2).and(e3), null);
	}

	/* 批量删除订单
	 * @see scau.erps.service.SystemOrderService#deleteOrders(java.util.List)
	 */
	@Override
	public void deleteOrders(List<SystemOrder> orders) {
		for (SystemOrder systemOrder : orders) {
			this.dao().delete(systemOrder);			
		}		
	}

	@Override
	public SystemOrder getSystemOrderById(int id) {		
		return this.fetch(id);
	}

	@Override
	public List<SystemOrder> getAllSystemOrders() {
		return this.query(null, null);
	}

}
